define(['jquery'], function() {

    // 推广cookie-------------start-----------------------------------------------------------



setTimeout(function () {
	$.ajax({
		method: 'GET',
		url: document.location.protocol+'//www.xmy'+url_func()+'/index.php?do=ajax&view=tool_click&statistic=1&sp_url=' + location.href,
		dataType: 'jsonp',
		jsonp:'callback'
	})
},1500);



var cookiepre = '';
var cookiedomain = '';
var cookiepath = '';
function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	cookieName = cookiepre + cookieName;
	expires.setTime(expires.getTime() + seconds * 1000);
	domain = !domain ? cookiedomain : domain;
	path = !path ? cookiepath : path;
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
					+ (expires ? '; expires=' + expires.toGMTString() : '')
					+ (path ? '; path=' + path : '/')
					+ (domain ? '; domain=' + domain : '')
					+ (secure ? '; secure' : '');
}

function getcookie(name) {
	name = cookiepre + name;
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(';', cookie_start);
	// return cookie_start==-1 ? '' : unescape(decodeURI(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length))));
	return cookie_start==-1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

if (document.referrer) {
	var referrer = document.createElement('a');
	referrer.href = document.referrer;
	if (referrer.hostname != document.domain) {
		var access_parse = document.domain.split('.');
		var access_refer = referrer.hostname.split('.');
		if (access_parse[access_parse.length - 2] != access_refer[access_refer.length - 2]) {
			setcookie('access_origin', document.referrer, 86400, '/', '.' + access_parse[access_parse.length - 2] + '.' + access_parse[access_parse.length - 1]);
		}
	}
}


var path_zturl = window.location.host;
path_zturl = path_zturl.replace(/^[a-zA-Z0-9-]+\./, '');

if (!getcookie('epweike_zturl')) {
	setcookie('epweike_zturl', window.location.href, 86400, '/',path_zturl);
	setcookie('epweike_zturl_back', window.location.href,86400,'/',path_zturl);
}

if (!getcookie('epweike_construction_epi')) {
	setcookie('epweike_construction_epi', "construction_epi", 86400, '/',path_zturl);
}

if (!getcookie('user_prom_event')) {
	var temp_pei =GetQueryString("epi");
	if(temp_pei !=null && temp_pei.toString().length>1)
	{
		setcookie('user_prom_event', temp_pei, 86400, '/',path_zturl);
	}
}

	var access_origin=getcookie('access_origin');
	var newMallUrl = window.location.href;
/*	var url1 = window.location.href;

	var url2 = self.location.href;

	var url3 = document.URL;

	var url4 = document.location;

	console.log(url1);
	console.log(url2);
	console.log(url3);
	console.log(url4);
	return false;*/
	var uri=window.location.href;
	var regx_1 = /^http:\/\/yx\.xmy\.(me|cn|us|com)\//;
	var regx_2=/^http:\/\/www\.epyxw\.(me|cn|us|net|com)\/(zt|solution)\//;

	if(regx_1.test(newMallUrl)){
		var preg123 = "yx";
		var mall_location_href=window.location.href;
		mall_location_href = mall_location_href.replace(preg123,'www');
		uri=mall_location_href;
		console.log(access_origin+','+uri);

	}
	if(regx_2.test(newMallUrl)){
		var preg12 = "epyxw";
		var mall_location_href=window.location.href;
		mall_location_href = mall_location_href.replace(preg12,'xmy');
		uri=mall_location_href;
		console.log(access_origin+','+uri);
	}
	if(!access_origin){
		access_origin=window.location.href;
	}
	// console.log(access_origin);
	// console.log(uri);
	$.ajax({
		method: 'GET',
		url: document.location.protocol+'//www.xmy'+url_func()+'/ztiframe.php',
		dataType: 'jsonp',
		jsonp:'callback',
		data:{
			'url':location.href,
			'access_origin':access_origin,
			'uri':uri
		}
	})




function url_func(){
	var url = window.location.host,cookiepath='/',cookiedomain='/';
	url = url.substring(url.lastIndexOf('.'));
	if (url == '.cn') {
		url = '.com'
	}
	return url;
}

function GetQueryString(name)
{
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r!=null)return  unescape(r[2]); return null;
}

// ----------------------end------------------------------------------------------




    
    // 百度统计代码

    if(App.baidu_id){

        require(['https://s11.cnzz.com/z_stat.php?id=1261009377&web_id=1261009377'],function(){
            var _hmt = _hmt || [];

            (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?5d636ddb16a6d94b2f460e306e2fda30";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();

        })

    }

    // 今日头条统计代码

    if(App.convert_id){

        (function(root) {
            root._tt_config = true;
            var ta = document.createElement('script'); ta.type = 'text/javascript'; ta.async = true;
            ta.src = document.location.protocol + '//' + 's1.pstatp.com/bytecom/resource/track_log/src/toutiao-track-log.js';
            ta.onerror = function () {
                var request = new XMLHttpRequest();
                var web_url = window.encodeURIComponent(window.location.href);
                var js_url  = ta.src;
                var url = '//ad.toutiao.com/link_monitor/cdn_failed?web_url=' + web_url + '&js_url=' + js_url + '&convert_id='+App.convert_id;
                request.open('GET', url, true);
                request.send(null);
            };
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(ta, s);
        })(window);

    };

});
